<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>{:C('WEB_SITE_TITLE')}</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <link href="__RES__/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
        <link href="__RES__/css/style.css" rel="stylesheet" type="text/css"/>

        <script src="__RES__/js/jquery-1.11.1.min.js" type="text/javascript"></script>
        <script src="__RES__/js/bootstrap.min.js" type="text/javascript"></script>

        <style type="text/css">
            nav .des-info{
                padding:12px 5px;
            }

            #pdoc_carousel img{
                margin: 0 auto;
            }
            nav div{
                display: inline-block;
            }
        </style>

    </head>
    <body>

        <header class="navbar navbar-fixed-top bs-docs-nav" id="top" role="banner">
            <div class="container">
                <div class="navbar-header">
                    <a class="navbar-brand" href="#">
                        <img src="__RES__/img/brand.jpg" alt=""/>
                    </a>
                </div>
                <nav class="collapse navbar-collapse" role="navigation">
                    <div class="des-info">
                        <span class="label label-primary">您好：{$_SESSION.current_member.real_name}</span>
                    </div>


                    <div class="des-info">
                        <span>{$pdoc.pdoc_name}</span>
                    </div>

                    <div class="des-info">
                        <span id="spanShowTime">已学习时间：</span>
                    </div>

                    <div class="des-info">
                        <span class="label label-info" id="s_cur_page">当前页码 00</span>
                        /
                        <span class="label label-info">共 {$pdoc.pdoc_pic_number} 页</span>
                    </div>

                    <div class="nav navbar-nav navbar-right" style="margin-top:5px;">
                        <button type="button" class="btn btn-primary" id="btnSave">保存返回</button>
                    </div>
                </nav>
            </div>
        </header>

        <div id="pdoc_carousel" class="carousel slide" data-ride="carousel" data-interval="false" style="border: 1px solid #000">

            <!-- Wrapper for slides -->
            <div class="carousel-inner" role="listbox">

                <div class="item active">
                    <img src="__UPLOAD__/index.jpg" alt="" />
                </div>

                <volist name="imgs" id="img">
                    <div class="item">
                        <img src="__UPLOAD__/{$img}" alt=""/>
                    </div>
                </volist>

            </div>

            <!-- Controls -->
            <a class="left carousel-control" href="#pdoc_carousel" role="button" data-slide="prev">
                <span class="glyphicon glyphicon-chevron-left"></span>
                <span class="sr-only">Previous</span>
            </a>
            <a class="right carousel-control" href="#pdoc_carousel" role="button"  data-slide="next">
                <span class="glyphicon glyphicon-chevron-right"></span>
                <span class="sr-only">Next</span>
            </a>
        </div>

        <script type="text/javascript">

            //var learnTime = {$time_study | default = 0};
            var learnTime = 0;
            var hour, min, sec;
            var t;

            function timeCount() {
                hour = parseInt(learnTime / 3600); // 小时数  
                min = parseInt(learnTime / 60); // 分钟数  
                if (min >= 60) {
                    min = min % 60;
                }
                sec = learnTime % 60;

                $("#spanShowTime").text("已学习时间：" + hour + "小时" + min + "分" + sec + "秒");

                learnTime++;

                t = setTimeout("timeCount()", 1000);
            }

            function stopTimeCount() {
                clearTimeout(t);
            }


        </script>

        <script>
            $(function () {


                var flag = 0;
                $('#pdoc_carousel').on('slid.bs.carousel', function () {
                    var str = $("#pdoc_carousel div.active img").attr("src");
                    var temp = str.match(/\/(\d)+./gi);
                    var page = "00";
                    if (temp !== "" && temp !== null) {
                        page = temp[0].substring(1, temp[0].length - 1);
                    }
                    $("#s_cur_page").text("当前页码 " + page);
                    //console.log(str);
                });

                $("#btnExit").click(function (event) {
                    /* Act on the event */
                    stopTimeCount();
                    location.href = "{:U('PdocList/index')}";
                });



                $("#btnSave").click(function (event) {
                    /* Act on the event */
                    
//                    if( learnTime < 120){
//                        alert("学习时间低于2分钟，不能保存！");
//                        return;
//                    }
                    
                    var uid = "{$_SESSION.current_member.uid}" || 0;
                    var pdoc_id = "{$pdoc.pdoc_id}" || 0;

                    var sendData = {
                        "uid": uid,
                        "pdoc_id": pdoc_id,
                        "time_study": learnTime
                    };


                    $.post("{:U('saveTimeStudy')}", sendData).done(function (responseData) {
                        flag = 1;
                        if (responseData.status === 1) {
                            alert(responseData.info);
                            location.href = responseData.jumpUrl;
                        } else {
                            alert(responseData.info);
                            location.href = responseData.jumpUrl;
                        }

                    });
                });


                window.onbeforeunload = function (event) {
                    $.post("{:U(clearSession)}");
                    if (flag !== 1) {
                        return "请点击'保存退出'，否则不会记录学习时间！";
                    }
                };


                $("#pdoc_carousel").mouseenter(function (e) {
                    timeCount();
                    // console.log("X:" + e.pageX + "   Y:" + e.pageY); 
                });

                $("#pdoc_carousel").mouseleave(function () {
                    stopTimeCount();
                    // console.log("out");
                });



            });
        </script>
    </body>
</html>
